﻿using ARS.Common.Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace ARS.Common.Service.ExecScripts
{
    /// <summary>
    /// SQL server调用
    /// </summary>
    public class SqlExecScript : IExecScript
    {
        public Tuple<DataSet, bool, string> ExecSql(string coonStr, string script)
        {

            using (SqlConnection con = new SqlConnection(coonStr))
            {
                DataSet ds = new DataSet();
                var isOK = false;
                var message = "";
                try
                {
                  
                  
                    SqlDataAdapter da = new SqlDataAdapter(script, con);
                   // SqlCommand comm = new SqlCommand(script, con);
                    //System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
                    //System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(SQLString, connection);
                    //comm.CommandTimeout = commTime;
                    da.SelectCommand.CommandTimeout =300;
                   
                    da.Fill(ds);
                    da.Dispose();
                    isOK = true;
                }
                catch (Exception ex)
                {
                    message = $"出错信息:\r\n Message{ex.Message} \r\n StackTrace:{ex.StackTrace}";
                   // Log.WriteLine(message);
                }
                finally
                {
                    con.Close(); //关闭数据库
                }

                return Tuple.Create(ds, isOK, message);
            }
        }
    }
}
